SET(MODULE_NAME library)

IF(WIN32)
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/thirdparty/dlfcn/include"
                   )
LINK_DIRECTORIES("${PROJECT_SOURCE_DIR}/thirdparty/dlfcn/lib"
                )
ENDIF()

FILE(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/tsin/library/*.hpp)
FILE(GLOB FILES ${PROJECT_SOURCE_DIR}/src/tsin/library/*.cpp)

IF(TSIN_ENABLE_MEM_CHECK)
SET(MEMCHECK_FILES ${PROJECT_SOURCE_DIR}/src/tsin/MemCheckStub.cpp)
SET(FILES ${FILES}
          ${MEMCHECK_FILES})
SOURCE_GROUP("Memory Check" FILES ${MEMCHECK_FILES})
ADD_DEFINITIONS(-DTSIN_MEMCHECK)
ENDIF()

SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

ADD_LIBRARY(${MODULE_NAME} SHARED ${FILES} ${HEADERS})
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES COMPILE_DEFINITIONS "LIBRARY_DEFINITION")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES LINK_INTERFACE_LIBRARIES "")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES SUFFIX ".so")
SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES OUTPUT_NAME ${MODULE_NAME})
TARGET_LINK_LIBRARIES(${MODULE_NAME} dl tsin-input tsin-display tsin-util tsin-runtime scdl-core)
ADD_DEPENDENCIES(${MODULE_NAME} tsin-input tsin-display tsin-runtime tsin-util scdl-core)
INSTALL(TARGETS library DESTINATION .)
